<?php

class UsersController extends ApplicationController
{
    var $models = 'user';

    function index()
    {
        $this->renderAction('listing');
    }

    function listing()
    {
        $this->user_pages = $this->pagination_helper->getPaginator($this->User, array('items_per_page' => 10));        
        $this->users =& $this->User->find('all', $this->pagination_helper->getFindOptions($this->User));
    }

    function show()
    {
        $this->user =& $this->User->find(@$this->params['id']);
    }

    function add()
    {
        if(!empty($this->params['user'])){
            $this->User->setAttributes($this->params['user']);
            if ($this->Request->isPost() && $this->User->save()){
                $this->flash['notice'] = $this->t('User was successfully created.');
                $this->redirectTo(array('action' => 'show', 'id' => $this->User->getId()));
            }
        }
    }
    
    function edit()
    {
        if(!empty($this->params['id'])){
            if(empty($this->user->id) || $this->user->id != $this->params['id']){
                $this->user =& $this->User->find($this->params['id']);
            }
        }else{
            $this->redirectToAction('listing');
        }

        if(!empty($this->params['user'])){
            $this->user->setAttributes($this->params['user']);
            if($this->Request->isPost() && $this->user->save()){
                $this->flash['notice'] = $this->t('User was successfully updated.');
                $this->redirectTo(array('action' => 'show', 'id' => $this->user->getId()));
            }
        }
    }
        
    function destroy()
    {
        if(!empty($this->params['id'])){
            $this->user =& $this->User->find($this->params['id']);
            if($this->Request->isPost()){
                $this->user->destroy();
                $this->redirectTo(array('action' => 'listing'));
            }
        }
    }  
}

?>